package c.c.a;

import android.content.Context;
import android.text.TextUtils;
import b.i.b.f;
import com.bytedance.embedapplog.IOaidObserver;
import com.bytedance.embedapplog.IOaidObserver.Oaid;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import org.json.JSONException;
import org.json.JSONObject;

public final class c1 {
    public static final String i;
    public static final String j;
    public static IOaidObserver k;
    public static String l;
    public final ReentrantLock a = new ReentrantLock();
    public d1 b;
    public boolean c;
    public f1 d;
    public final Context e;
    public AtomicBoolean f = new AtomicBoolean(false);
    public Map<String, String> g;
    public Long h;

    public class a implements Runnable {
        /* JADX WARNING: Removed duplicated region for block: B:26:0x00d7 A:{Catch:{ all -> 0x0108 }} */
        /* JADX WARNING: Removed duplicated region for block: B:15:0x0074 A:{Catch:{ all -> 0x0108 }} */
        /* JADX WARNING: Removed duplicated region for block: B:28:0x00da A:{Catch:{ all -> 0x0108 }} */
        public void run() {
            /*
            r14 = this;
            r0 = c.c.a.c1.this;
            java.util.Objects.requireNonNull(r0);
            r1 = c.c.a.c1.j;
            r2 = 0;
            r3 = "Oaid#initOaid";
            c.c.a.u0.a(r1, r3, r2);
            r3 = r0.a;	 Catch:{ all -> 0x0108 }
            r3.lock();	 Catch:{ all -> 0x0108 }
            r3 = "Oaid#initOaid exec";
            c.c.a.u0.a(r1, r3, r2);	 Catch:{ all -> 0x0108 }
            r3 = r0.d;	 Catch:{ all -> 0x0108 }
            r3 = r3.a();	 Catch:{ all -> 0x0108 }
            r4 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0108 }
            r4.<init>();	 Catch:{ all -> 0x0108 }
            r5 = "Oaid#initOaid fetch=";
            r4.append(r5);	 Catch:{ all -> 0x0108 }
            r4.append(r3);	 Catch:{ all -> 0x0108 }
            r4 = r4.toString();	 Catch:{ all -> 0x0108 }
            c.c.a.u0.a(r1, r4, r2);	 Catch:{ all -> 0x0108 }
            if (r3 == 0) goto L_0x003d;
        L_0x0033:
            r4 = r3.a;	 Catch:{ all -> 0x0108 }
            c.c.a.c1.l = r4;	 Catch:{ all -> 0x0108 }
            r4 = r3.a();	 Catch:{ all -> 0x0108 }
            r0.g = r4;	 Catch:{ all -> 0x0108 }
        L_0x003d:
            r4 = android.os.SystemClock.elapsedRealtime();	 Catch:{ all -> 0x0108 }
            r6 = r0.e;	 Catch:{ all -> 0x0108 }
            r7 = r0.b;	 Catch:{ all -> 0x0108 }
            if (r7 == 0) goto L_0x0064;
        L_0x0047:
            r6 = r7.b(r6);	 Catch:{ all -> 0x0108 }
            if (r6 == 0) goto L_0x0064;
        L_0x004d:
            r7 = r6.a;	 Catch:{ all -> 0x0108 }
            r8 = r6.b;	 Catch:{ all -> 0x0108 }
            r8 = java.lang.Boolean.valueOf(r8);	 Catch:{ all -> 0x0108 }
            r9 = r6 instanceof c.c.a.w0.b;	 Catch:{ all -> 0x0108 }
            if (r9 == 0) goto L_0x0066;
        L_0x0059:
            r6 = (c.c.a.w0.b) r6;	 Catch:{ all -> 0x0108 }
            r9 = r6.c;	 Catch:{ all -> 0x0108 }
            r6 = java.lang.Long.valueOf(r9);	 Catch:{ all -> 0x0108 }
            r0.h = r6;	 Catch:{ all -> 0x0108 }
            goto L_0x0066;
        L_0x0064:
            r7 = r2;
            r8 = r7;
        L_0x0066:
            r6 = new android.util.Pair;	 Catch:{ all -> 0x0108 }
            r6.<init>(r7, r8);	 Catch:{ all -> 0x0108 }
            r7 = android.os.SystemClock.elapsedRealtime();	 Catch:{ all -> 0x0108 }
            r7 = r7 - r4;
            r4 = r6.first;	 Catch:{ all -> 0x0108 }
            if (r4 == 0) goto L_0x00d7;
        L_0x0074:
            r4 = 1;
            if (r3 == 0) goto L_0x0081;
        L_0x0077:
            r5 = r3.b;	 Catch:{ all -> 0x0108 }
            r3 = r3.f;	 Catch:{ all -> 0x0108 }
            r3 = r3.intValue();	 Catch:{ all -> 0x0108 }
            r3 = r3 + r4;
            goto L_0x0083;
        L_0x0081:
            r3 = -1;
            r5 = r2;
        L_0x0083:
            r9 = android.text.TextUtils.isEmpty(r5);	 Catch:{ all -> 0x0108 }
            if (r9 == 0) goto L_0x0091;
        L_0x0089:
            r5 = java.util.UUID.randomUUID();	 Catch:{ all -> 0x0108 }
            r5 = r5.toString();	 Catch:{ all -> 0x0108 }
        L_0x0091:
            if (r3 > 0) goto L_0x0094;
        L_0x0093:
            goto L_0x0095;
        L_0x0094:
            r4 = r3;
        L_0x0095:
            r11 = new c.c.a.e1;	 Catch:{ all -> 0x0108 }
            r3 = r6.first;	 Catch:{ all -> 0x0108 }
            r9 = r3;
            r9 = (java.lang.String) r9;	 Catch:{ all -> 0x0108 }
            r3 = r6.second;	 Catch:{ all -> 0x0108 }
            r6 = r3;
            r6 = (java.lang.Boolean) r6;	 Catch:{ all -> 0x0108 }
            r7 = java.lang.Long.valueOf(r7);	 Catch:{ all -> 0x0108 }
            r12 = java.lang.System.currentTimeMillis();	 Catch:{ all -> 0x0108 }
            r8 = java.lang.Long.valueOf(r12);	 Catch:{ all -> 0x0108 }
            r10 = java.lang.Integer.valueOf(r4);	 Catch:{ all -> 0x0108 }
            r12 = r0.h;	 Catch:{ all -> 0x0108 }
            r3 = r11;
            r4 = r9;
            r9 = r10;
            r10 = r12;
            r3.m831init(r4, r5, r6, r7, r8, r9, r10);	 Catch:{ all -> 0x0108 }
            r3 = r0.d;	 Catch:{ all -> 0x0108 }
            java.util.Objects.requireNonNull(r3);	 Catch:{ all -> 0x0108 }
            r3 = r3.a;	 Catch:{ all -> 0x0108 }
            r3 = r3.edit();	 Catch:{ all -> 0x0108 }
            r4 = r11.b();	 Catch:{ all -> 0x0108 }
            r4 = r4.toString();	 Catch:{ all -> 0x0108 }
            r5 = "oaid";
            r3 = r3.putString(r5, r4);	 Catch:{ all -> 0x0108 }
            r3.apply();	 Catch:{ all -> 0x0108 }
            goto L_0x00d8;
        L_0x00d7:
            r11 = r2;
        L_0x00d8:
            if (r11 == 0) goto L_0x00e4;
        L_0x00da:
            r3 = r11.a;	 Catch:{ all -> 0x0108 }
            c.c.a.c1.l = r3;	 Catch:{ all -> 0x0108 }
            r3 = r11.a();	 Catch:{ all -> 0x0108 }
            r0.g = r3;	 Catch:{ all -> 0x0108 }
        L_0x00e4:
            r3 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0108 }
            r3.<init>();	 Catch:{ all -> 0x0108 }
            r4 = "Oaid#initOaid oaidModel=";
            r3.append(r4);	 Catch:{ all -> 0x0108 }
            r3.append(r11);	 Catch:{ all -> 0x0108 }
            r3 = r3.toString();	 Catch:{ all -> 0x0108 }
            c.c.a.u0.a(r1, r3, r2);	 Catch:{ all -> 0x0108 }
            r0 = r0.a;
            r0.unlock();
            r0 = new com.bytedance.embedapplog.IOaidObserver$Oaid;
            r1 = c.c.a.c1.l;
            r0.m2494init(r1);
            c.c.a.c1.b(r0);
            return;
        L_0x0108:
            r1 = move-exception;
            r0 = r0.a;
            r0.unlock();
            r0 = new com.bytedance.embedapplog.IOaidObserver$Oaid;
            r2 = c.c.a.c1.l;
            r0.m2494init(r2);
            c.c.a.c1.b(r0);
            throw r1;
            */
            throw new UnsupportedOperationException("Method not decompiled: c.c.a.c1$a.run():void");
        }
    }

    static {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(c1.class.getSimpleName());
        stringBuilder.append("#");
        String stringBuilder2 = stringBuilder.toString();
        i = stringBuilder2;
        j = stringBuilder2;
    }

    public c1(Context context) {
        this.e = context;
        d1 e = f.e(context);
        this.b = e;
        if (e != null) {
            this.c = e.a(context);
        } else {
            this.c = false;
        }
        this.d = new f1(context);
    }

    public static void b(Oaid oaid) {
        IOaidObserver iOaidObserver = k;
        if (iOaidObserver != null) {
            iOaidObserver.onOaidLoaded(oaid);
        }
    }

    public static <K, V> void c(Map<K, V> map, K k, V v) {
        if (v != null) {
            map.put(k, v);
        }
    }

    public static void d(JSONObject jSONObject, String str, Object obj) {
        if (!TextUtils.isEmpty(str) && obj != null) {
            try {
                jSONObject.put(str, obj);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    public void a() {
        if (this.f.compareAndSet(false, true)) {
            a aVar = new a();
            String d = c.b.a.a.a.d(new StringBuilder(), j, "-query");
            if (TextUtils.isEmpty(d)) {
                d = "TrackerDr";
            }
            new Thread(new v0(aVar, d), d).start();
        }
    }
}
